package com.sdry.service.impl.hpf;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.mapper.hpf.TypeMapper;
import com.sdry.model.hpf.Type;
import com.sdry.service.hpf.TypeService;

/**
 * @ClassName: TypeServiceImpl 
 * @Description:产品型号Service实现
 * @Author hpf
 * @Date 2018年9月20日 下午3:21:17 
 * @version 1.0
 */
@Service
public class TypeServiceImpl implements TypeService {

	@Resource
	private TypeMapper typeMapper;
	
	/**
	 * 查询产品型号总数
	 * @param type
	 * @return
	 */
	public Integer countType(Type type) {
		// TODO Auto-generated method stub
		return typeMapper.countType(type);
	}

	/**
	 * 分页查询产平型号
	 * @param map
	 * @return
	 */
	public List<Type> listPageType(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return typeMapper.listPageType(map);
	}

	/**
	 * 新增产品型号
	 * @param type
	 * @return
	 */
	public Integer insertType(Type type) {
		// TODO Auto-generated method stub
		return typeMapper.insertType(type);
	}

	/**
	 * 修改产品型号
	 * @param type
	 * @return
	 */
	public Integer updateType(Type type) {
		// TODO Auto-generated method stub
		return typeMapper.updateType(type);
	}

	/**
	 * 删除产品型号
	 * @param tid
	 * @return
	 */
	public Integer deleteType(Long tid) {
		// TODO Auto-generated method stub
		return typeMapper.deleteType(tid);
	}
	
	/**
	 * 批量删除产品型号
	 * @param idArr
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public Integer deleteTypes(String [] idArr) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			for (int i = 0; i < idArr.length; i++) {
				isSuccess = typeMapper.deleteType(Long.parseLong(idArr[i]));
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}

}
